package com.atguigu.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassNAME RabbitMQConfig
 * @Description
 * @Author wuyafeng atguigu
 * @Date 2021/12/1 19:57
 * @Version 1.0
 **/
@Configuration
public class RabbitMQConfig {
    //通配符模式最多
    //交换机名称
    public static final String EXCHANGE_NAME = "boot_topic_exchange";
    //队列名称
    public static final String QUEUE_NAME ="boot_queue";

    //1.创建交换机
    @Bean("bootExchage")
    public Exchange bootExchage() {
        return ExchangeBuilder.topicExchange(EXCHANGE_NAME).durable(true).build();
    }

    //2.创建队列
    @Bean("bootQueue")
    public Queue bootQueue(){
        return QueueBuilder.durable(QUEUE_NAME).build();
    }

    //3.队列和交换机的绑定  @Qualifier 指定注入哪个对象
    @Bean
    public Binding bindingQueueExchange(@Qualifier("bootQueue") Queue queue,
                                        @Qualifier("bootExchage") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("boot.#").noargs();
    }

}
